import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.imageio.ImageIO;

public class Map {
	
	private final int DEFAULT_TILE_TOTAL = 10;
	ArrayList<Tile> tileArray;
	ArrayList<Exit> exitArray;
	
	int rowLength;
	int colLength;
	int tileBase;
	String bgImageName;
	
	int heroStartRow;
	int heroStartCol;
	
	int exits;
	
	String mapName;
	String actionListFileName;
	Exit theExit;
	
	public Map(){
		
		mapName = "";
		actionListFileName = "";
		
		tileArray = new ArrayList();
		exitArray = new ArrayList();
		
		rowLength = DEFAULT_TILE_TOTAL;
		colLength = DEFAULT_TILE_TOTAL;
		tileBase = DEFAULT_TILE_TOTAL;
		bgImageName = "";
		
		heroStartRow = 0;
		heroStartCol = 0;
		
		exits = 0;
	}
	public boolean isTileAnExit(int row, int col){
		int exitTotal = exitArray.size();
		//Tile tile  = this.getTileAt(row, col);
		Exit exit = new Exit();
		boolean isAnExit = false;
		for(int i=0;i<exitTotal;i++){
			exit = (Exit) exitArray.get(i);
			if(exit.getExitCol()==col && exit.getExitRow() == row){
				isAnExit = true;
				theExit = exit;
			}
		}
		return isAnExit;
	}
	
	public Tile getTileAt(int row, int col) {
		
		boolean foundTile = false;
		Tile tile = new Tile();
		int tileCounter = 0;
		while(foundTile == false &&  tileCounter < tileArray.size()){
			
			tile = (Tile) tileArray.get(tileCounter);
			
			
			if(tile.getCol() == col && tile.getRow() == row)
					foundTile=true;
		
			
			tileCounter++;
			
		}
		
		return tile;
	}
	
	public int getTileArraySize()
	{
		return tileArray.size();
	}
	
	public int getExitArraySize(){
		return exitArray.size();
	}
	
	public void addTile(Tile tile) {
		tileArray.add(tile);
				
	}
	
	public void addTile(int index, Tile tile) {
		tileArray.add(index, tile);
				
	}
	
	public void addExit(Exit exit){
		exitArray.add(exit);
	}
	
	public Exit getExitAt(int index){
		return (Exit) exitArray.get(index);
	}
		
	public int getRowLength() {
		return rowLength;
	}

	public void setRowLength(int rowLength) {
		this.rowLength = rowLength;
	}

	public int getColLength() {
		return colLength;
	}

	public void setColLength(int colLength) {
		this.colLength = colLength;
	}

	public int getTileBase() {
		return tileBase;
	}

	public void setTileBase(int tileBase) {
		this.tileBase = tileBase;
	}

	public String getBgImageName() {
		return bgImageName;
	}

	public void setBgImageName(String bgImageName) {
		this.bgImageName = bgImageName;
	}

	public int getHeroStartRow() {
		return heroStartRow;
	}

	public void setHeroStartRow(int heroStartRow) {
		this.heroStartRow = heroStartRow;
	}

	public int getHeroStartCol() {
		return heroStartCol;
	}

	public void setHeroStartCol(int heroStartCol) {
		this.heroStartCol = heroStartCol;
	}

	public int getExits() {
		return exits;
	}

	public void setExits(int exits) {
		this.exits = exits;
	}

	public String getMapName() {
		return mapName;
	}

	public void setMapName(String mapName) {
		this.mapName = mapName;
	}
	public Exit getTheExit() {
		return theExit;
	}
	public void setTheExit(Exit theExit) {
		this.theExit = theExit;
	}
	public String getActionListFileName() {
		return actionListFileName;
	}
	public void setActionListFileName(String actionListFileName) {
		this.actionListFileName = actionListFileName;
	}
	
	

}
